package com.example.shixunandjavagotoyangchen.Eternity.LoginActivity;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * 作者:二徒
 * 时间：2021/11/12- 11:19
 * 功能实现：
 */
public class LoginOkhttp {

   public static LoginOkhttp loginOkhttp;
   public Retrofit retrofit;
   public static LoginOkhttp getLoginOkhttp(){
       if (loginOkhttp==null){
           synchronized (LoginOkhttp.class){
               if (loginOkhttp==null){
                   loginOkhttp = new LoginOkhttp();
               }
           }
       }
       return loginOkhttp;
   }


   public Retrofit getRetrofit()
   {
       if (retrofit==null){
           synchronized (Retrofit.class){
               if (retrofit==null){
                   retrofit = new Retrofit.Builder()
                           .baseUrl("https://www.wanandroid.com/")
                           .client(new OkHttpClient.Builder()
                                   .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                                   .build())
                           .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                           .addConverterFactory(GsonConverterFactory.create())
                           .build();
               }
           }
       }
       return retrofit;
   }
}
